package CtrLayer;

import java.util.ArrayList;

import ModelLayer.City;
import ModelLayer.Customer;
import DBLayer.DBCity;
import DBLayer.DBCustomer;

public class CustomerCtr {
	private DBCustomer customerDB; 
	private DBCity cityDB;
	
	/*
	 * Constructor
	 */
	public CustomerCtr()
	{
		customerDB = new DBCustomer();
		cityDB = new DBCity();
	}

	public City getCity(int codeZip) throws NumberFormatException
	{
		return cityDB.getCityByCodeZip(codeZip, false);
	}
	
	
	public void createCustomer(String name, String address, int codeZip, String city, int phoneNo, String email, String cprCvr) 
	{
		Customer customer = new Customer(name, address, codeZip, city, phoneNo, email, cprCvr);
		customerDB.insertCustomer(customer);
	}

	public Customer getCustomerByPhoneNo(int phoneNo)
	{
		Customer tempCustomer = customerDB.getCustomerByPhoneNo(phoneNo, false);
		return tempCustomer;
	}
	
	public ArrayList<Customer> getAllCustomers()
	{
		return customerDB.getAllCustomers(false);
	}

	public int updateCustomer(String _name, String _address, int _codeZip, String _city, int _phoneNo, String _email, String _cprCvr)
	{	
		Customer c = new Customer();
		c.setName(_name);
		c.setAddress(_address);
		c.setCodeZip(_codeZip);
		c.setCity(getCity(_codeZip).getCity());
		c.setEmail(_email);
		c.setCprCvr(_cprCvr);
	
		return customerDB.updateCustomer(c);
	}

	public int deleteCustomer(int phoneNo)
	{
		return customerDB.deleteCustomer(phoneNo);	
	}
}
